<!DOCTYPE HTML>
<html>
<head th:include="fragments/_header :: _head('添加资源')"></head>
<body>
<article class="page-container">
    <form class="form form-horizontal" id="form-admin-add">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>资源名：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" th:value="${resources?.name}" placeholder="" id="name"
                       name="name">
                <input th:if="${resources}" type="hidden" class="input-text" th:value="${resources.id}" placeholder=""
                       id="id" name="id">
                <input type="hidden" class="input-text" th:value="${pid}" placeholder="" id="pid" name="pid">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>类型：</label>
            <div class="formControls col-xs-8 col-sm-9 skin-minimal">
                <div class="radio-box">
                    <input name="type" type="radio" id="sex-1" th:checked=${resources?.type==1} value="1">
                    <label for="sex-1">菜单</label>
                </div>
                <div class="radio-box">
                    <input type="radio" id="sex-2" name="type" th:checked=${resources?.type==2} value="2">
                    <label for="sex-2">按钮</label>
                </div>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>编码：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" th:value="${resources?.code}" placeholder="" id="code"
                       name="code">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>链接：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" th:value="${resources?.url}" placeholder="" id="url" name="url">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>排序：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" th:value="${resources?.sort}" placeholder="" id="sort"
                       name="sort">
            </div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>
<div th:include="fragments/_footer :: _footer"></div>
<script type="text/javascript" src="/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
    $(function () {
        $("#form-admin-add").validate({
            rules: {
                name: {
                    required: true,
                    minlength: 2,
                    maxlength: 16
                },
                type: {
                    required: true
                },
                code: {
                    required: true
                },
                url: {
                    required: true
                },
                sort: {
                    required: true,
                    digits: true
                }
            },
            onkeyup: false,
            focusCleanup: true,
            success: "valid",
            submitHandler: function (form) {
                $(form).ajaxSubmit({
                    type: 'post',
                    url: "/resources/add",
                    success: function (result) {
                        if (result.success) {
                            layer.msg("添加成功", {icon: 1, time: 1000});
                            parent.window.location.reload();
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000});
                        }
                    },
                    error: function (XmlHttpRequest, textStatus, errorThrown) {
                        layer.msg('error!', {icon: 1, time: 1000});
                    }
                });
            }
        });
    });
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>